<script setup>
import { ref, toRefs, inject, getCurrentInstance } from 'vue'
const props = defineProps({
  agentConfig: {
    type: Object,
    default: {},
  },
})
const emits = defineEmits(['emitSend'])
const showUserInput = inject('showUserInput')
const messages = inject('messages')
const { appContext } = getCurrentInstance()
const proxy = appContext.config.globalProperties
const showForm = inject('showForm')

const { agentConfig } = toRefs(props)

// 从agentConfig中解构参数
const {
  model_config: { opening_statement = '' },
} = agentConfig.value

// 推荐问题
let hotKnowledgeArray =
  agentConfig.value?.model_config.suggested_questions || []
const initialData = ref(hotKnowledgeArray)

// 点击列表
const handleClick = (item) => {
  // console.log(`output->item`,item)
  emits('emitSend', item)
}

const handleShowForm = () => {
  if (messages.value.length > 1) {
    proxy.$toast('对话已开始，无法修改对话设置')
    return
  }
  showForm.value = true
}
</script>

<template>
  <div class="welcome-container">
    <div class="welcome-text">
      <p>{{ opening_statement }}</p>
      <div class="userSet" v-if="showUserInput" @click="handleShowForm">
        <img src="../../../assets/img/usrset.png" />
        <span>开始前，您可以修改对话设置</span>
        <!-- <van-icon name="arrow" /> -->
      </div>
    </div>
    <div
      class="suggest-wrap"
      v-for="(c_item, c_index) in initialData"
      :key="c_index"
    >
      <div class="suggest-item" @click="handleClick(c_item)">
        <div class="suggest-text">{{ c_item }}</div>
        <van-icon name="arrow" class="arrow" />
      </div>
    </div>
  </div>
</template>
<style lang="less" scoped>
.welcome-container {
  border-radius: 0.16rem;
  margin-bottom: 0.2rem;
  .welcome-text {
    margin-bottom: 0.24rem;
    font-size: 0.28rem;
    font-weight: bold;
    font-family: PingFangSC, PingFang SC;
    font-weight: 400;
    color: #222222;
    background: #fefefe;
    border-radius: 0.16rem;
    padding: 0.32rem;
    .userSet {
      margin-top: 0.24rem;
      background: #eef8ff;
      // width: 5.5rem;
      display: flex;
      align-items: center;
      padding: 0.2rem;
      height: 0.6rem;
      border-radius: 0.16rem;
      img {
        width: 0.34rem;
        height: 0.34rem;
        margin-right: 0.1rem;
      }
    }
  }
  .suggest-wrap {
    .suggest-item {
      position: relative;
      display: inline-block;
      background: #fefefe;
      opacity: 0.8;
      border-radius: 0.16rem;
      padding: 0.22rem 0.32rem;
      font-size: 0.24rem;
      font-family: PingFangSC, PingFang SC;
      font-weight: 400;
      color: #333333;
      margin-bottom: 0.24rem;
      padding-right: .85rem;
    }
    .arrow{
      position: absolute;
      right: .2rem;
      top: 50%;
      transform: translateY(-50%);
    }
    
  }
}
</style>
